/// <reference path="jquery.min.js" />
/// <reference path="rsseasy.min.js" />
/// <reference path="iscroll.min.js" />
/// <reference path="md5.min.js" />
/// <reference path="../data/arealist.js" />
/// <reference path="webviewadapter.min.js" />
/// <reference path="validated.min.js" />
/// <reference path="../data/arealist.js" />
/// <reference path="../data/dictdata.js" />
//api地址www.caidan.zhongqijuyi.com||api.caidan360.com
var wwwhost = "http://api.caidan360.com/", apihost = wwwhost + "api/", upfilehost = wwwhost + "upfile/", allpage = $("section"), curpage = "#shenghuopage", prevpage = "#shenghuopage", menulink = $("body>footer>a"), curmenu = menulink.first(), winw = $(window).width(), winh = $(window).height();
var javawwwhost = "http://127.0.0.1:8080/";
//var javawwwhost = "http://112.74.133.120:8090/"
var javahost = javawwwhost + "caidanxiaoyuan/";
function scl(e){
	$('#sidebar a').removeClass("now");
	$('#sidebar h1').removeClass("nowh1");
	$('a[id='+e+']').addClass("now");
	$('a[id='+e+']').parent("li").find("h1").addClass("nowh1");
	var a = $("div[id="+e+"]").offset().top;
	var b = $("div[id="+e+"]").offset().left;
	scrollBarTop(a-$("div[id="+e+"]").height());
}
$("#orderform").attr("action", javahost + "pay/pay");

$("section").width(winw).height(winh);
var myid = 0, shangjiamyid = 83, userdata = eval("(" + (Storage.Get("userdata") || "{}") + ")"), prikey = "www.rsseasy.com";

var systime = new Date(), systimetick = 0, taskitem = {};
$.post(javahost + "time/", function (time)
{
    systime = new Date(parseInt(time) * 1000);
    setInterval(function ()
    {
        systimetick = systime.addSeconds(1) / 1000;
        $.each(taskitem, function (k, v)
        {
            if (v && v.constructor == Function) {
                v();
            }
        })
    }, 1000);

    //初始化日期选择框
    $(function ()
    {
        var dt = new Date(systime), html = "";
        dt.setDate(dt.getDate() - 1);
        dt.setHours(0);
        dt.setMinutes(0);
        dt.setMilliseconds(0);
        dt.setSeconds(0);
        for (var i = 0; i < 60; i++) {
            dt.setDate(dt.getDate() + 1);
            html += '<li time="' + dt.getTime() + '">' + dt.toString("MM月dd日") + '</li>';
        }
        $("#selectyearitem").html(html);

        html = '';
        for (i = 0; i < 24; i++) {
            html += '<li time="' + i + '">' + (i < 10 ? "0" + i : i) + '</li>';
        }
        $("#selecthouritem").html(html);

        html = '';
        for (i = 0; i < 60; i++) {
            html += '<li time="' + i + '">' + (i < 10 ? "0" + i : i) + '</li>';
        }
        $("#selectminutesitem").html(html);

        $("#shijianselectwrap div").selectslide({
            "dis": 20,
            "onslideend": function (json)
            {

            }
        });
    });
});

var historyitem = {}

$(".historyback").click(function (ev)
{
	console.info(ev)
    ev.preventDefault();
});

menulink.click(function ()
{
    if (!IsLogin(true) && $(this).index() == 3) {
        return;
    }
    menulink.removeClass();
    $(this).addClass("active");
    JsAdapter.ClearHistory({}).Submit();
});
//单页切换
window.onhashchange = function ()
{
    allpage.hide();
    var hash = location.hash;
    $(prevpage).unload();
    if (hash) {
        prevpage = curpage;
        curpage = hash;
        menulink.filter("[href='" + hash + "']").click();
        $(hash).show().load();
        JsAdapter.GetNetState({}).Submit();
        return;
    }
    allpage.first().show().load();
}
window.onhashchange();

$(document).ready(function ()
{
    if (!Storage.Get("launch")) {
        Storage.Set("launch", "1");

        var guidepage = $("#guidepage");
        guidepage.find("li").width(winw);
        guidepage.find("li").height(winh);
        guidepage.find("li div").not("#guidemenustart").width(winw);
        guidepage.find("li div").not("#guidemenustart").height(winh);
        guidepage.show().find("ul").width(winw * 5);
        guidepage.find("ul").pageslide({
            "onslideend": function (json)
            {
                if (json["curpage"] == json["totalpage"]) {
                    //guidepage.hide();
                }
            }
        });
    }
});
function clickLi(e){
	$(e).siblings().removeClass("active");
	$(e).addClass("active");
	var flid = e.id;
    $.getJSON(javahost + "shenghuo/list", datasign({fenleiid:e.id}), function (json)
    {
        var html = "", tejia = json["data"], sichunv = json["sichunv"], sichunan = json["sichunan"], guohe = json["guohe"], meigui = json["meigui"];
        $.each(tejia, function (idx, data)
        {
//        	if(flid==1){
//        		html += '<div><a shenghuoid="' + data["id"] + '" href="#shenghuoviewpage"><img src="' + upfilehost + data["ico"] + '" /></a><div class="shtitle"><h2>' + data["mingcheng"] + (data["kucun"] == 0 ? '<img src="img/sell.png" />' : "") + '</h2><span>' + (data["kaiqiangshijian"] + "").replace(/^(\d{2})(\d{2})$/, "$1:$2") + '开抢</span></div></div>';
//        	}else{
//	        	html += '<li class="new-mu_l2">'
//						+'		      <a shenghuoid="' + data["id"] + '" href="#shenghuoviewpage" class="new-mu_l2a">'
//						+'            <span class="new-mu_tmb"><img src="' + upfilehost + data["ico"] + '"  width="100" height="100"  alt=""/></span>'
//						+'	             <span class="new-mu_l2cw">' 
//						+'	                  <strong class="new-mu_l2h">'+data["mingcheng"]+'</strong>'
//						+'	                  <span class="new-mu_l2h new-mu_l2h-v1"><span class="new-txt-rd2"></span></span>'
//						+'	                  <span class="new-mu_l2c new-p-re"><strong class="new-txt-rd2">&yen;' + data["jiage"] + '</strong>'
//						+'							<span class="new-txt-price" style="color:red"></span>'
//						+'					 </span>   '                 
//						+'	             </span>'
//						+'       </a>'
//						+'  </li>'
//        	}
        	/*html = '<div class="swiper-slide">'
        	if(flid==1){
        		html += '<div><a shenghuoid="' + data["id"] + '" href="#shenghuoviewpage"><img src="' + upfilehost + data["ico"] + '" /></a><div class="shtitle"><h2>' + data["mingcheng"] + (data["kucun"] == 0 ? '<img src="img/sell.png" />' : "") + '</h2><span>' + (data["kaiqiangshijian"] + "").replace(/^(\d{2})(\d{2})$/, "$1:$2") + '开抢</span></div></div>';
        	}
        	html +='</div>';*/
        		/*else{
        		html += +'<div style="width: 100%;">'
	        	+'<div style="float: left;width: 30%;height: 99px;background-image:' + upfilehost + data["ico"] + '"></div>'
	        	+'<div style="float: left;width: 70%;height: 99px;">'
	        	+'	<div style="height: 30px;"><span>'+data["mingcheng"]+'</span></div>'
	        	+'	<div style="height: 39px;"><span>'+data["mingcheng"]+'</span></div>'
	        	+'	<div style="height: 30px;"><span>' + data["jiage"] +'</span></div>'
	        	+'	</div>'
	        	+'</div>'
        	}*/
        });
        shenghuoart.html(html);
        shenghuoart.addClass("hide");
        shenghuoart.find("a").click(function ()
        {
            shenghuoid = $(this).attr("shenghuoid");
        });
    });

}


$("#guidemenustart").click(function ()
{
    $("#guidepage").hide();
});

function datasign(params)
{
    var tmp = [];
    $.each(function (key, val)
    {
        tmp.push(key);
    });
    tmp.sort();

    var objarr = [];
    $.each(function (idx, val)
    {
        objarr.push(val + "=" + objarr[val]);
    });
    tmp = objarr.join("&");
    $.extend(params, { "sign": MD5(tmp + "&key=" + prikey) });

    return params;
}

//表单参数扩展
function requestdata(params, array)
{
    if (array) {
        $.each(array, function (k, v)
        {
            params[v["name"]] = v["value"];
        });
    }
    return params;
}


function IsLogin(login)  //获取用户MYID，判断用户是否登录
{
    myid = userdata["myid"] || 0;
    if (!login && !myid) {
        location.href = "#loginpage";
    }
    return myid;
}

function IsRenZheng()
{
    if (userdata["isrenzheng"] != "2") {
        $("#tipsmsgwrap,#tipsmsg").show();
        return false;
    }
    return true;
}

function IsCloseRenZheng()
{
    $("#tipsmsgwrap,#tipsmsg").hide();
}

$("#loginpage header .historyback").unbind().click(function ()
{
    JsAdapter.onRollBack();
});
JsAdapter.onRollBack = function ()
{
    if (curpage == "payokpage" || curpage == "paypage") {
        location.href = "#shenghuopage";
        return;
    }

    if (!IsLogin(true) && (prevpage == "#mypage" || prevpage == "#getpwd" || prevpage == "#regpage")) {
        history.go(-2);
        //location.href="#shenghuopage";
    }
    else {
        history.back();
    }
}


//-----------------------即时通信开始
//当准备就绪时,由ready调用后回调
ImAdapter.onReady = function ()
{
    if (IsLogin(true)) {
        this.UserLogin(myid);  //用户登录
    }
}
//当用户登录成功
ImAdapter.onUserLogin = function ()
{
}

//获取离线聊天内容
ImAdapter.onGetChatList = function (json)
{
}

//当接收到聊天信息时
ImAdapter.onReceiveChat = function (myid, data, shijian)
{
}

//当接收到通知时
ImAdapter.onReceiveNotify = function (data, marker)
{
    data = data.toJson();
    JsAdapter.Notity({ "title": data["title"], "message": data["message"], "transmarker": data["marker"] }).Submit();
}
//ImAdapter.Ready(wwwhost);
//--------------------------即时通信开始

//彩生活
var shenghuoart = $("#shenghuopage  article"), shenghuoid = 0;
var fenlei = $("#shenghuopage  ul")
$("#shenghuopage").load(function ()
{
    shenghuoart.removeClass("hide");
    $.getJSON(javahost + "shenghuo/list", datasign({pageSize:50}), function (json)
    {
        var html = "", tejia = json["data"], sichunv = json["sichunv"], sichunan = json["sichunan"], guohe = json["guohe"], meigui = json["meigui"];
        var jl = 0;
        $.each(tejia, function (idx, data)
        {
        	if(idx==0){
        		html += '<div id="chapter'+data['fenleiid']+'">';
        	}
        	if(data['fenleiid']==1){
        		//html += '<div id=""><a shenghuoid="' + data["id"] + '" href="#shenghuoviewpage"><img src="' + upfilehost + data["ico"] + '" /></a><div class="shtitle"><h2>' + data["mingcheng"] + (data["kucun"] == 0 ? '<img src="img/sell.png" />' : "") + '</h2><span>' + (data["kaiqiangshijian"] + "").replace(/^(\d{2})(\d{2})$/, "$1:$2") + '开抢</span></div></div>';
        		html += '<div class="sp">'
			        	+'<a shenghuoid="' + data["id"] + '" href="#shenghuoviewpage"><div style="float: left;width: 30%;height: 100px;"><img style="width:100%; height:100%;" src="' + upfilehost + data["ico"] + '"></div>'
			        	+'<div class="new-mu_l2h" style="float: left;width: 70%;height:100px;">'
				        	+'	<h1>'
				        	+'	<span class="huodongspan">'+data["mingcheng"]+'</span>'
				        	+'	</h1>'
				        	+'	<p></p>'
				        	+'	<div style="height: 40px;">'
				        	+'		<div style="width:50%;height: 40px; line-height: 40px;float: left;"><span class="price">¥' + data["jiage"] +'</span></div>'
				        	+'		<div class="shtitle">' + (data["kucun"] == 0 ? '<img src="img/sell.png" />' : "") + '<span class="clock">' + (data["kaiqiangshijian"] + "").replace(/^(\d{2})(\d{2})$/, "$1:$2") + '开抢</span></div>'
				        	+'	</div></a>'
		        		+'</div>'
	        		+'</div>'
        	}else{
        		if(data['fenleiid']!=jl){
	        		html +='</div>';
	        		if(tejia.length!=idx){
	        			html +='<div id="chapter'+data['fenleiid']+'">';
	        		}
        		}
    			html += '<div class="sp">'
				        	+'<a shenghuoid="' + data["id"] + '" href="#shenghuoviewpage"><div style="float: left;width: 30%;height: 100px;"><img style="width:100%; height:100%;" src="' + upfilehost + data["ico"] + '"></div>'
				        	+'<div class="new-mu_l2h" style="float: left;width: 70%;height:100px;">'
				        	+'	<h1 >'
				        	+'	<span class="huodongspan">'+data["mingcheng"]+'</span>'
				        	+'	</h1>'
				        	+'	<div style="height: 40px;"><span class="price">¥' + data["jiage"] +'</span></div>'
				        	+'	</div></a>'
		        		+'</div>'
        	}
        	jl = data['fenleiid'];
        });
        html +='</div>';
        shenghuoart.html(html);
        shenghuoart.addClass("hide");
        shenghuoart.find("a").click(function ()
        {
            shenghuoid = $(this).attr("shenghuoid");
        });
        fenlei.html('');
    	$.getJSON(javahost + "category/", function (json){
    		var html = "";

    		 $.each(json, function (idx, data)
            {
    			 if(idx==0){
    				 html +='<li><a onclick="scl(\'chapter'+data['id']+'\')" href="javascript:void(0);" id="chapter'+data['id']+'" class="now">'+data["name"]+'</a><h1 class="nowh1"></h1></li>';
    			 }else{
    				 html +='<li><a onclick="scl(\'chapter'+data['id']+'\')" href="javascript:void(0);" id="chapter'+data['id']+'" >'+data["name"]+'</a><h1 ></h1></li>';
    			 }
            });
    		fenlei.html(html);
    	});
    });
}).load();



$.getJSON(javahost + "shenghuo/shijian", function (json)
{
    var data = {}, html = "";
    $.each(json, function (key, val)
    {
        data[val["id"]] = val["shijian"];
        html += '<input type="radio" id="sendshijian' + val["id"] + '" name="sendshijian" value="' + val["id"] + '" /><label for="sendshijian' + val["id"] + '">' + val["shijian"] + '</label>';
    });
    $("#sendshijianwrap").html(html);
    dictdata.songdashijian = data;
});
var yingyestopshijian = "171500";
$.getJSON(javahost + "shenghuo/xianshi", function (json)
{
    xiaoshifen = parseInt(json["xianshi"]) || 20;
    yingyestopshijian = json["xiabanshijian"] || "171500"
});

//彩生活详情页
var shenghuoviewpage = $("#shenghuoviewpage"),shenghuoviewfooter = $("#shenghuoviewfooter"), kaiqianbtn = $("#kaiqianbtn"), shenghuokucun = 0, shenghuoshuliang = shenghuoviewpage.find("footer span"), shenghuodanjia = 0, payjifen = null, zongjiawrap = $(".zongjia"), zongjifen = 0, istejia = false;;
shenghuoviewpage.load(function ()
{
    var article = shenghuoviewpage.find("article").empty();
    shenghuokucun = 10000;
    article.removeClass("hide");
    shenghuoviewpage.find("footer span").html("1");
    shenghuoviewpage.find("footer a").html("");
    zongjiawrap.hide();
    kaiqianbtn.empty();
    $.get(javahost + "shenghuo/view", { "id": shenghuoid }, function (data)
    {
        $("#mingcheng").val(data["mingcheng"]);
        $("#show_url").val("http://localhost/index.html#errorpage");
      
        ShareData.title = data["mingcheng"];
        ShareData.desc = (data["miaoshu"] + "").delHtml();
        ShareData.imgurl = upfilehost + data["ico"];
        ShareData.url = javahost + "/shenghuo/shenghuo?id=" + shenghuoid;
        
        zongjia = shenghuodanjia = parseFloat(data["jiage"]).round(2);

        shenghuoviewpage.find("header h1").html(data["mingcheng"]);
        zongjiawrap.html("￥" + shenghuodanjia).show();

        payjifen = data["payjifen"];
        article.addClass("hide");

        kaiqianbtn.removeClass();
        if (taskitem["shenghuokaiqiang"]) {
            delete taskitem["shenghuokaiqiang"];
        }
        istejia = false;
        if (payjifen) {
            istejia = true;
            zongjifen = parseInt(userdata["jifen"]);
            article.html((IsLogin(true) ? "<ul><li>消耗积分：<span>" + payjifen + "</span>积分</li><li>可用积分：<span>" + userdata["jifen"] + "</span>积分</li></ul>" : '') + data["miaoshu"]);

            $(".jifen").html("（消耗 " + payjifen + "积分）");

            shenghuokucun = parseInt(data["kucun"]);

            if (!shenghuokucun) {
                kaiqianbtn.addClass("disabled").html("已售完");
                return;
            }
            
            shenghuoviewpage.find("footer a").html("仅剩" + shenghuokucun + "份");
            if (payjifen && parseInt(payjifen) > parseInt(userdata["jifen"])) {
                kaiqianbtn.addClass("disabled").html("积分不够");
                return;
            }
            kaiqiangshijian = data["kaiqiangshijian"];
            shenghuokaiqiang();
        }
        else {
        	shenghuoviewfooter.css("position","fixed");
            $(".jifen").hide();
            kaiqianbtn.addClass("allow").html("<a href='#dingdanpage'>购买</a>");
            article.html(data["miaoshu"]);
        }
    }, "json");
});
$("#kaiqianbtn").click(function (ev)
{
    if (!IsLogin() || !$(this).hasClass("allow")) {
        ev.preventDefault();
        return;
    }
    if (systime.toString("HHmmss") > yingyestopshijian) {
        ev.preventDefault();
        alert("温馨提示:店小二回家了，彩生活每天的营业时间为:上午9:00-下午17:00\n赶快到彩活动和彩市场中狂欢吧！");
    }
});

var shuliang = 1, zongjia = 0;
shenghuoviewpage.find("footer img").click(function ()
{
    shuliang = parseInt(shenghuoshuliang.html()) || 1;
    if ($(this).index()) {
        shuliang++;
    }
    else if (--shuliang <= 0) {
        shuliang = 1;
    }

    if (shenghuokucun && shuliang > shenghuokucun) {
        shuliang = shenghuokucun;
    }

    shenghuoshuliang.html(shuliang);
    zongjia = (shuliang * shenghuodanjia).toString().round(2);
    zongjiawrap.html("￥" + zongjia);
    if (payjifen && shenghuokucun && systime.toString("HHmm") > kaiqiangshijian) {
        var usejifen = shuliang * payjifen;
        shenghuoviewpage.find("article>ul").find("span").first().html(usejifen);
        $(".jifen").html("（消耗 " + usejifen + "积分）");
        if (usejifen > zongjifen) {
            kaiqianbtn.removeClass("allow").addClass("disabled").html("积分不够");
            return;
        }
        else {
            kaiqianbtn.removeClass("disabled").addClass("allow").html("<a href='#dingdanpage'>马上抢</a>");
        }

        //shenghuokaiqiang(parseInt(data["kaiqiangshijian"]));
    }
});

var kaiqiangshijian = "1100", xiaoshifen = 15;
function shenghuokaiqiang()
{
    taskitem["shenghuokaiqiang"] = function ()
    {
        if (systime.toString("HHmm") < kaiqiangshijian) {
            kaiqianbtn.addClass("kaiqiang").html((kaiqiangshijian + "").replace(/^(\d{2})(\d{2})$/, "$1:$2") + "<br />开抢");
            return;
        }
        kaiqianbtn.addClass("allow").html("<a href='#dingdanpage'>马上抢</a>");
        taskitem["shenghuokaiqiang"] = null;
    }
}

$("#dingdanpage").load(function ()
{
    var curdt = new Date(systimetick * 1000);
    curdt.setMinutes(curdt.getMinutes() + xiaoshifen);
    curdt = curdt.toString("HH:mm");
    $("#sendshijianwrap input").each(function (k, v)
    {
        if (curdt > dictdata.songdashijian[v.value]) {
            $(v).next().hide();
        }
    });
});

JsAdapter.onWeiXinPay = function (json)
{
    if (Storage.Get("istejia") == "1") {
        location.href = "index.html#paypage";
    }
    else {
        location.href = "index.html#payokpage";
    }
}

var dingdandata = {};
JsAdapter.onWeiXinOrder = function (json)
{
	alert(json)
    JsAdapter.WeiXinPay(json).Submit();
}

//订单提交
$("#dingdansubmit").click(function (ev)
{
    if (IsLogin()) {
        ev.preventDefault();

        var sendshijian = $("#sendshijianwrap input:checked").val();
        if (!sendshijian) {
            alert("请选择送达时间！");
            return;
        }

        if(dictdata.songdashijian[sendshijian].replace(":","")-systime.toString("HHmm")<xiaoshifen) {
            alert("送达时间超过下单时间，请重新选择！");
            return;
        }
        var dizhiid = userdata["dizhiid"];
       
        if(dizhiid==null||dizhiid==''){
        	alert("请设置收货地址！");
            return;
        }
        if (!dizhiid) {
            alert("请设置收货地址！");
            return;
        }

        JsAdapter.Progress({ "style": true, "message": "正在准备订单" }).Submit();

        var pay = $("#paywrap input:checked").val();


        $.getJSON(javahost + "shenghuo/dingdan", { "myid": myid, "shenghuoid": shenghuoid, "jiage": shenghuodanjia, "shuliang": shuliang, "zongjia": zongjia, "usejifen": payjifen, "dizhiid": dizhiid, "sendshijian": sendshijian, "pay": pay }, function (json)
        {
            JsAdapter.Progress({ "action": "hide" }).Submit();
            if (json["code"]) {
                alert(dictdata.infocode[json["code"]]);
                return;
            }
            Storage.Set("istejia", istejia ? 1 : 0);
            Storage.Set("orderid", json["dingdanid"]);

            if (pay == 2) {
                JsAdapter.WeiXinOrder({ "out_trade_no": json["dingdanid"], "body": $("#mingcheng").val(), "total_fee": zongjia * 100, "attach": myid }).Submit();
                return;
            }

            $("#fee").val(zongjia.toString().round(2));
            $("#orderid").val(json["dingdanid"]);
            document.getElementById("orderform").submit();
        });
    }
});

$("#zacaidanbtn").click(function ()
{
    $("#payokpage").find("h4,div").show();
    $.get(javahost + "shenghuo/jifen", { "orderid": Storage.Get("orderid") }, function (data)
    {
        $("#payokpage").find("b").html("+" + data);
    });
});
$("#payokpage button").click(function ()
{
    $("#payokpage").find("h4,div").hide();
    location.href = "index.html#shenghuopage";
});

//登录
$(function ()
{
    var loginaccount = $("#loginaccount");
    loginaccount.keydown(function (ev)
    {
        if (ev.keyCode != 8 && this.value.replace(/\s/mg, "").length > 10) {
            return false;
        }
    });
    loginaccount.keyup(function ()
    {
        loginaccount.removeAttr("allow");
        if (this.value.match(/^(\d{3})\s?(\d{4})\s?(\d{4})$/)) {
            this.value = RegExp.$1 + " " + RegExp.$2 + " " + RegExp.$3;
            loginaccount.attr("allow", "allow");
        }
        loginstatus();
    });

    var loginpwd = $("#loginpwd");
    loginpwd.keyup(function ()
    {
        loginpwd.removeAttr("allow");
        if (this.value.match(/^.{6,}$/)) {
            loginpwd.attr("allow", "allow");
        }
        loginstatus();
    });

    var loginbtn = $("#loginbtn");

    function loginstatus()
    {
        loginbtn.removeClass();
        if ($("#loginpage").find("[allow]").length == 2) {
            loginbtn.addClass("allow");
        }
    }

    loginbtn.click(function ()
    {
        var account = loginaccount.val().replace(/\s/mg, "");
        if (!account.match(/^\d{11}$/)) {
            loginaccount.removeClass().addClass("error");
            return;
        }
        var pwd = loginpwd.val();
        if (!pwd.match(/^.{6,}$/)) {
            loginpwd.removeClass().addClass("error");
            return;
        }
        JsAdapter.Progress({ "style": true, "message": "正在登录" }).Submit();
        $.getJSON(javahost + "user/login", { "account": account, "pwd": pwd }, function (json)
        {
            JsAdapter.Progress({ "action": "hide" }).Submit();
            if (json['infocode']) {
                alert(dictdata.infocode[json['infocode']]);
                return;
            }
            updateuserdata(json);
            switch (prevpage) {
                case "#regpage":
                case "#getpwd":
                case "#setpwdpage":
                    prevpage = "#mypage";
                    break;
            }
            location.replace(location.search + prevpage)
        });
    });

});

//彩市场
var shoppageart = $("#shoppage article"), shichangid = 0, shoplistwrap = shoppageart.find(">div"), shopcurpage = 1, shoptotalpage = 0, refreshtime = 0, shichangupdate = true;
$("#shoppage").load(function ()
{
    $.getJSON(javahost + "shop/list", { "pageNum": shichangupdate ? 1 : shopcurpage, "refreshtime": refreshtime }, function (json)
    {
        refreshtime = json["time"];
        shoptotalpage = parseInt(json["totalpage"]) || shoptotalpage;
        var html = '';
        $.each(json["data"], function (idx, data)
        {
            html += '<table><tr><td><div><img src="' + upfilehost + data["avatar"] + '" /></div></td><td><h2>' + data["nickname"] + '</h2><h3>' + new Date(data["shijian"] * 1000).toString("yyyy-MM-dd HH:mm:ss") + '</h3></td><td>￥' + data["jiage"] + '</td></tr></table>';
            html += '<ul><li><a dataid="' + data["id"] + '" href="#shichangview"><img src="' + upfilehost + data["tu1"].replace(".", "l.") + '" /></a></li>' + (data['tu2'] ? '<li><a dataid="' + data["id"] + '" href="#shichangview"><img src="' + upfilehost + data["tu2"].replace(".", "l.") + '" /></a></li>' : '') + (data['tu3'] ? '<li><a dataid="' + data["id"] + '" href="#shichangview"><img src="' + upfilehost + data["tu3"].replace(".", "l.") + '" /></a></li>' : '') + '</ul>';
            html += '<table><tr><td><img src="img/shichang/f' + data["leixingid"] + '.png" /></td><td><a dataid="' + data["id"] + '" href="#shichangview">' + (data["jieshao"].length > 30 ? data["jieshao"].substring(0, 30) : data["jieshao"]) + '</a></td></tr></table>';
        });

        html = $(html);

        html.find("[dataid]").click(function ()
        {
            shichangid = $(this).attr("dataid");
        });
        shoppageart.addClass("hide");

        if (!shichangupdate && shopcurpage > 1) {
            shoplistwrap.append(html);
            return;
        }
        if (json["data"].length) {
            if (shoplistwrap.children().length) {
                html.insertBefore(shoplistwrap.children().first());
            }
            else {
                shoplistwrap.append(html);
            }
        }
        shichangupdate = true;
    });
}).find('.right').click(function (ev)
{
    if (!IsLogin() || !IsRenZheng()) {
        ev.preventDefault();
    }
    document.getElementById("shopform").reset();
    shopfabulist.html('<li><a href="#selectephoto"><img id="shopplusbtn" src="img/shop/plus.png" /></a></li>');
    myshopid = 0;
});
shoppageart.moveajax({
    "update": function ()
    {
        shichangupdate = true;
        $("#shoppage").load();
    },
    "next": function ()
    {
        shichangupdate = false;
        if (shopcurpage < shoptotalpage) {
            shopcurpage++;
            $("#shoppage").load();
        }
    }
});

var shopliuyanlist = $("#shopliuyanlist"), shichangviewart = $("#shichangview article");
$("#shichangview").load(function ()
{
    shichangviewart.removeClass("hide");
    $("#shopinfo").html('<br /><br /><br />');
    $.getJSON(javahost + "shop/view", { "id": shichangid }, function (data)
    {
        if (data["state"] == "0") {
            alert("商品已下架或已被删除！");
            history.back();
            return;
        }
        shichangviewart.addClass("hide");
        var html = '<h2>￥' + data['jiage'] + '<img src="img/shichang/f' + data["leixingid"] + '.png" /></h2><p>' + data["jieshao"] + '</p><a href="#photoview"><img src="' + upfilehost + data["tu1"] + '" />' + (data["tu2"] ? '<img src="' + upfilehost + data["tu2"] + '" />' : '') + (data["tu3"] ? '<img src="' + upfilehost + data["tu3"] + '" />' : '') + '</a>';
        $("#shopinfo").html(html);

        ShareData.title = ShareData.desc = data["jieshao"];
        ShareData.url = javahost + "h5/shichang?id=" + shichangid;
        ShareData.imgurl = upfilehost + data["tu1"];

        $("#photoview ul").html('<li><img src="' + upfilehost + data["tu1"] + '" /></li>' + (data["tu2"] ? '<li><img src="' + upfilehost + data["tu2"] + '" /></li>' : '') + (data["tu3"] ? '<li><img src="' + upfilehost + data["tu3"] + '" /></li>' : '')).width(winw * 3).pageslide();
        $("#photoview ul").find("li").width(winw);


    });
    shopliuyanlist.empty();
    $.getJSON(javahost + "shop/liuyan/list", { "shopid": shichangid }, function (json)
    {
        var html = "";
        $.each(json['data'], function (idx, data)
        {
            html += '<li nickname="' + data["nickname"] + '"><table><tr><td><div><img src="' + upfilehost + data["avatar"] + '" /></div></td><td>' + data["nickname"] + '</td><td>' + new Date(data["shijian"] * 1000).toString("yyyy-MM-dd HH:mm:ss") + '</td></tr></table><p>' + (data["neirong"].replace(/^(@[^\s]{1,10})/, '回复<span>$1</span>')) + '</p></li>';
        });
        shopliuyanlist.html(html);
        shopliuyanlist.find("[nickname]").click(function ()
        {
            $("#shopliuyan").val("@" + $(this).attr("nickname") + " ");
        });
    });
});


$("#photoview").load(function ()
{
    $(this).find("img").vcenter();
});

var shopliuyan = $("#shopliuyan");
$("#shopliuyan,#huodongliuyan").on("touchstart ", function (ev)
{
    if (ev.keyCode == 229) {
        return false;
    }
});
$("#shopliuyanbtn").click(function ()
{
    if (!IsLogin()) {
        return;
    }
    if (shopliuyan.val().replace(/\s+/mg, "").length == 0) {
        shopliuyan.focus();
        return;
    }
    JsAdapter.Progress({ "style": true, "message": "正在提交" }).Submit();
    $.post(javahost + "shop/liuyan/edit", { "neirong": shopliuyan.val(), "myid": myid, "shopid": shichangid }, function (json)
    {
        var html = '<li nickname="' + userdata["nickname"] + '"><table><tr><td><div><img src="' + upfilehost + userdata["avatar"] + '" /></div></td><td>' + userdata["nickname"] + '</td><td>' + new Date().toString("yyyy-MM-dd HH:mm:ss") + '</td></tr></table><p>' + (shopliuyan.val().replace(/^(@[^\s]{1,10})/, '回复<span>$1</span>')) + '</p></li>';
        if (shopliuyanlist.find(">li").length) {
            $(html).insertBefore(shopliuyanlist.find(">li").first()).click(function ()
            {
                $("#shopliuyan").val("@" + $(this).attr("nickname") + " ");
            });
        }
        else {
            shopliuyanlist.append(html).find(">li").first().click(function ()
            {
                $("#shopliuyan").val("@" + $(this).attr("nickname") + " ");
            });
        }
        shopliuyan.val("");
        JsAdapter.Progress({ "action": "hide" }).Submit();
    }, "json");
});

$("#loginpage article b").click(function ()
{
    var loginpwd = $("#loginpwd");
    loginpwd.attr("type", loginpwd.attr("type") == "password" ? "text" : "password");
    $(this).css("margin-top", loginpwd.attr("type") != "password" ? "-0.8rem" : "-0.68rem").find("img").attr("src", loginpwd.attr("type") != "password" ? "img/user/eyeopen.png" : "img/user/eye.png");
});
$("#regpage article b").click(function ()
{
    var regpwd = $("#regpwd");
    regpwd.attr("type", regpwd.attr("type") == "password" ? "text" : "password");
    $(this).css("margin-top", regpwd.attr("type") != "password" ? "-0.8rem" : "-0.68rem").find("img").attr("src", regpwd.attr("type") != "password" ? "img/user/eyeopen.png" : "img/user/eye.png");
});

//注册
$(function ()
{
    var smsbtn = $("#regpage p"), regjishi = 60, jishi = 60, regtelphone = $("#regtelphone"), smstick = null, sendsmscode = 0;

    smsbtn.click(function ()
    {
        var telphone = regtelphone.val();

        if (telphone.match(/^\d{11}$/)) {
            if (regjishi == 60) {
                regjishi--
                smstick = setInterval(function ()
                {
                    if (regjishi <= 0) {
                        regjishi = 60;
                        smsbtn.html("重新发送");
                        clearInterval(smstick);
                        return;
                    }
                    smsbtn.html(regjishi + "秒后重发");
                    regjishi--;
                }, 1000);
                $.get(javahost + "user/sendsms", { "telphone": telphone, "action": "reg" }, function (data)
                {
                    switch (data) {
                        case "15":
                        case "16":
                            regjishi = 60;
                            clearInterval(smstick);
                            smsbtn.html("获取验证码");
                            alert(dictdata.infocode[data]);
                            break;
                        default:
                            sendsmscode = data;
                            break;
                    }
                });
            }
            return;
        }
        alert("请输入正确的手机号码");
    });

    var regbtn = $("#regbtn");
    regbtn.click(function ()
    {
        try {
            var telphone = regtelphone.val();
            if (!telphone.match(/^\d{11}$/)) {
                throw "6";
            }

            var regcode = $("#regcode").val();
            if (regcode.trim()!=sendsmscode.trim()) {
                throw "3";
            }

            var regnickname = $("#regnickname").val();
            if (!regnickname.match(/^.{1,10}$/)) {
                throw "5";
            }

            var regpwd = $("#regpwd").val();
            if (!regpwd.match(/^.{6,}$/)) {
                throw "7";
            }

            JsAdapter.Progress({ "style": true, "message": "正在注册" }).Submit();
            $.post(javahost + "user/reg", $("#regform").serialize() + "&smscode=" + sendsmscode, function (json)
            {
                if (dictdata.infocode[json["infocode"]]) {
                    alert(dictdata.infocode[json["infocode"]]);
                    return;
                }
                updateuserdata(json);
                JsAdapter.Progress({ "action": "hide" }).Submit();
                location.href = "#mypage";
            }, 'json');
        } catch (e) {
            alert(dictdata.infocode[e]);
        }
    });

    //忘记密码
    var pwdcodep = $("#getpwd article p");
    pwdcodep.click(function ()
    {

        var telphone = pwdaccount.val();

        if (telphone.match(/^\d{11}$/)) {
            if (jishi == 60) {
                jishi--;
                smstick = setInterval(function ()
                {
                    if (jishi <= 0) {
                        jishi = 60;
                        pwdcodep.html("重新发送");
                        clearInterval(smstick);
                        return;
                    }
                    pwdcodep.html(jishi + "秒后重发");
                    jishi--;
                }, 1000);
                $.get(javahost + "user/sendsms", { "telphone": pwdaccount.val(), "action": "pwd" }, function (data)
                {
                    switch (data) {
                        case "15":
                        case "16":
                            jishi = 60;
                            pwdcodep.html("发送验证码");
                            clearInterval(smstick);
                            alert(dictdata.infocode[data]);
                            break;
                        default:
                            sendsmscode = data;
                            break;
                    }
                });
            }
            return;
        }
        alert("请输入正确的手机号码");
    });

    var nextbtn = $("#nextbtn"), pwdcode = $("#pwdcode"), pwdaccount = $("#pwdaccount");
    $("#pwdcode,#pwdaccount").keyup(function ()
    {
        nextbtn.removeClass();
        if (pwdaccount.val().match(/^\d{11}$/) && pwdcode.val().match(/^\d{4}$/)) {
            nextbtn.addClass("allow");
        }
    });
    nextbtn.click(function ()
    {
        if (pwdcode.val().trim()!=sendsmscode.trim()) {
            alert("验证码错误！");
            return;
        }
        if (nextbtn.hasClass("allow")) {
            location.replace("#setpwdpage");
        }
    });

    var setpwd = $("#setpwd"), setrepwd = $("#setrepwd"), setnewsbtn = $("#setnewsbtn");
    $("#setpwd,#setrepwd").keyup(function ()
    {
        setnewsbtn.removeClass();
        if (setpwd.val().length > 5 && setpwd.val() == setrepwd.val()) {
            setnewsbtn.addClass("allow");
        }
    });
    setnewsbtn.click(function ()
    {
        if (nextbtn.hasClass("allow")) {
            $.get(javahost + "user/resetpwd", { "account": pwdaccount.val(), "pwd": setpwd.val() }, function (data)
            {
                location.replace("#loginpage");
            });
        }
    });
});


//彩中心
$("#mypage").load(function ()
{
    if (IsLogin()) {
        $.getJSON(javahost + "user/view", { "myid": myid }, function (data)
        {
            updateuserdata(data);
        })
    }
});

JsAdapter.onGetVersion = function (json)
{
    $("#aboutpage h2").html("彩蛋校园  V" + json["name"]);
}
$("#aboutpage").load(function ()
{
    JsAdapter.GetVersion().Submit();
});
$("#aboutpage button").click(function ()
{
    userdata = {};
    Storage.remove("userdata");
    Storage.remove("userdata");
    updateuserdata({});
    location.href = "#shenghuopage";
});
$("#aboutpage h2").click(function ()
{
    JsAdapter.UpdateVersion().Submit();
});


$("#dizhipage").load(function ()
{
    IsLogin();
});
$("#dizhipage header .right").click(function ()
{
    if (IsLogin()) {
        var dizhi = $("#dizhi").val();
        var params = { "shengid": $("[name='shengid']:checked").val(), "shiid": $("[name='shiid']:checked").val(), "xianid": $("[name='xianid']:checked").val(), "dizhi": dizhi, "myid": myid };
        JsAdapter.Progress({ "style": true, "message": "数据更新中" }).Submit();
        $.post(javahost + "user/dizhi", params, function (json)
        {
            JsAdapter.Progress({ "action": "hide" }).Submit();
            if (json["infocode"]) {
                alert(dictdata.infocode[json["infocode"]]);
                return;
            }
            $.extend(params, json);
            updateuserdata(params);
            history.back();
        }, 'json');
    }
});
//我的订单
var mydingdanlist = $("#mydingdan table"), mydingdanart = $("#mydingdan article"), dingdanid = 0, dingdancurpage = 1, dingdantotalnumber = 0;
function loaddingdandata(update)
{
    if (IsLogin()) {
        mydingdanart.removeClass("hide");
        $.getJSON(javahost + "user/dingdan", { "myid": myid, "pageNum": dingdancurpage }, function (json)
        {
            dingdantotalnumber = parseInt(json["totalpage"]);
            mydingdanart.addClass("hide");
            var html = '';
            $.each(json["data"], function (k, v)
            {
                html += '<tr><td><div><img src="' + upfilehost + v["ico"] + '" /></div></td><td><ul><li>' + v["mingcheng"] + '<span>' + dictdata["dingdanstate"][v["state"]] + '</span></li><li>￥' + v["jiage"] + " X " + v["shuliang"] + '<a ' + (v["state"] == "2" ? " href='#mypingjia' dingdanid='" + v["id"] + "' class='allow'" : "") + '>评价得积分</a></li><li>送达时间 ' + dictdata["songdashijian"][v["sendshijian"]] + '</li></ul></td></tr>';
            });
            html = $(html);
            html.find("a").click(function ()
            {
                dingdanid = $(this).attr("dingdanid");
            });
            if (dingdancurpage != 1 && dingdancurpage < dingdantotalnumber) {
                mydingdanlist.append(html);
                dingdancurpage++;
            }
            else {
                mydingdanlist.html(html);
            }
        });
    }
}
$("#mydingdan").load(function ()
{
    loaddingdandata();
});
mydingdanart.moveajax({
    "update": function ()
    {
    },
    "next": function ()
    {
        loaddingdandata();
    }
});

$("#mypingjia .right").click(function (ev)
{
    ev.preventDefault();
    JsAdapter.Progress({ "style": true, "message": "正在提交中" }).Submit();
    $.post(javahost + "shenghuo/pingjia", $("#pingjiaform").serialize() + "&dingdanid=" + dingdanid + "&myid=" + myid, function (json)
    {
        JsAdapter.Progress({ "action": "hide" }).Submit();
        alert("已提交！");
        history.back();
    }, "json");
});

//我发布的商品
var myshoplist = $("#myshop ul"), myshopart = $("#myshop article"), myshoppage = 1, myshopid = 0, myshoptotalpage = 0;
function shoplistparse()
{
    var html = "";
    $.getJSON(javahost + "shenghuo/shop", { "myid": myid, "pageNum": myshoppage }, function (json)
    {
        myshoptotalpage = parseInt(json["totalpage"]);
        $.each(json["data"], function (idx, data)
        {
            html += '<li><table><tr><td><div dataid="' + data["id"] + '"><img src="' + upfilehost + data['tu1'] + '"/></div></td><td><h2 dataid="' + data["id"] + '">' + (data["jieshao"].length > 30 ? data["jieshao"].substring(0, 30) : data["jieshao"]) + '</h2><h4>￥' + data["jiage"] + '</h4><h3>' + new Date(data['shijian'] * 1000).toString("yyyy-MM-dd HH:mm:ss") + '<a myshopid="' + data["id"] + '" href="#shopfabupage">编辑</a></h3></td><td delete="' + data["id"] + '">删除</td></tr></table></li>';
        });

        html = $(html);
        html.find("[delete]").click(function ()
        {
            $(this).parent().parent().parent().parent().remove();
            $.getJSON(javahost + "shop/delete", { "id": $(this).attr("delete") }, function (data)
            {
                alert(dictdata.infocode[data]);
            });
        });

        html.find("[dataid]").click(function ()
        {
            shichangid = $(this).attr("dataid");
            location.href = "#shichangview";
        });

        myshopart.addClass("hide");
        if (myshoppage != 1 && myshoppage < myshoptotalpage) {
            myshoplist.append(html);
            myshoppage++;
        }
        else {
            myshoplist.html(html);
        }
        myshopart.unbind().moveajax({
            "slide": true,
            "update": function (json)
            {
            },
            "next": function ()
            {
                shoplistparse();
            }
        });

        myshoplist.find('a').unbind().click(function (ev)
        {
            ev.stopPropagation();
            myshopid = $(this).attr("myshopid")
            document.getElementById("shopform").reset();
            shopfabulist.html('<li><a href="#selectephoto"><img id="shopplusbtn" src="img/shop/plus.png" /></a></li>');

            $.getJSON(javahost + "shop/view", { "id": myshopid }, function (data)
            {
                $("[name='leixingid']").val([data["leixingid"]]);
                $("#shangpinjiage").val(data["jiage"]);
                $("#shangpingjieshao").val(data["jieshao"]);

                var html = data["tu1"] ? '<li><img src="' + upfilehost + data["tu1"] + '" /><input type="hidden" id="tu1" name="tu1" value="' + data["tu1"] + '"/><h2></h2></li>' : '';
                if (data["tu1"]) {
                    html += data["tu2"] ? '<li><img src="' + upfilehost + data["tu2"] + '" /><input type="hidden" id="tu2" name="tu2" value="' + data["tu2"] + '"/><h2></h2></li>' : '';
                    if (data["tu3"]) {
                        html += '<li><img src="' + upfilehost + data["tu3"] + '" /><input type="hidden" id="tu3" name="tu3" value="' + data["tu3"] + '"/><h2></h2></li>';
                    }
                }

                shopfabulist.html(html);

                shopfabulist.find('input').each(function ()
                {
                    if (!this.value) {
                        $(this).parent().remove();
                    }
                });
                if (shopfabulist.find('li').length < 3) {
                    shopfabulist.append('<li><a href="#selectephoto"><img id="shopplusbtn" src="img/shop/plus.png" /></a></li>');
                }

                shopfabulist.find("h2").click(function ()
                {
                    $(this).parent().remove();
                    shopfabulist.find('input').each(function (idx)
                    {
                        $(this).attr("name", "tu" + (idx + 1)).attr("id", "tu" + (idx + 1));
                    });
                    //$.getJSON(apihost+"shop/deltu.php?id="+myshopid+"&"+$(this).prev().attr("id")+"=");
                    if (!$("#shopplusbtn").length) {
                        shopfabulist.append('<li><a href="#selectephoto"><img id="shopplusbtn" src="img/shop/plus.png" /></a></li>');
                    }
                });
            });
        });
    });
}
$("#myshop").load(function ()
{
    if (IsLogin()) {
        shoplistparse('next');
    }
});

//彩市场发布
var shopfabulist = $("#shopform ul");
$(function ()
{
    $("#shopfabupage").load(function ()
    {
        IsLogin();
    });

    $("[name='jiage']").keyup(function ()
    {
        validate();
    });
    $("[name='jieshao']").keyup(function ()
    {
        validate();
    });

    var right = $("#shopfabupage .right");
    function validate()
    {
        right.removeClass("allow");
        if ($("#shangpinjiage").val().match(Validated.moneyrule) && $("#shangpingjieshao").val().replace(/\s/mg, "").match(/^.{2,250}$/)) {
            right.addClass("allow");
        }
    }

    right.click(function ()
    {
        validate();
        if (!$(this).hasClass("allow")) {
            alert("请填写商品价格与商品信息！");
            return;
        }
        if ($("#shopform ul input").length == 0) {
            alert("请上传至少1张商品图片");
            return;
        }
        JsAdapter.Progress({ "style": true, "message": "正在发布..." }).Submit();
        $.post(apihost + "shop/edit", $("#shopform").serialize() + "&action=" + (myshopid ? "update" : "append") + "&myid=" + myid + "&id=" + myshopid, function (json)
        {
            JsAdapter.Progress({ "action": "hide" }).Submit();
            alert("发布成功！");
            history.back();
        });
    });
});

var photolist = $("#selectephoto article ul")
JsAdapter.onGalleryList = function (json)
{
    var li = photolist.append('<li><input type="radio" id="p' + json["id"] + '" name="shopphoto" value="' + json["path"] + '" /><label></label><label for="p' + json["id"] + '"><img src="' + (json["base64"] ? 'data:image/png;base64,' + json["base64"] : json["path"]) + '" /></label></li>');
}
var GalleryListReady = true;
JsAdapter.onGalleryListComplete = function ()
{
    GalleryListReady = true;
}
JsAdapter.onTakePhotos = function (json)
{
    $('<li><input type="radio" id="p' + json["id"] + '" name="shopphoto" value="' + json["path"] + '" /><label></label><label for="p' + json["id"] + '"><img src="' + (json["base64"] ? 'data:image/png;base64,' + json["base64"] : json["path"]) + '" /></label></li>').insertAfter(photolist.find("li").first());
}

//选择图片
$("#selectephoto").load(function ()
{
    if (GalleryListReady) {
        GalleryListReady = false;
        var list = photolist.find("li");
        photolist.find("li").not(list.first()).remove();
        JsAdapter.GalleryList({ width: 120 }).Submit();
    }
});
$("#selectephoto li").first().click(function ()
{
    if (upfiletpye == "useravatarbtn") {
        JsAdapter.TakePhotos({ "action": "cutupload", "transmarker": "useravatarbtn" }).Submit();
    }
    else {
        JsAdapter.TakePhotos({ "action": "upload", "cutwidth": 160, "transmarker": "useravatarbtn" }).Submit();
    }
});
JsAdapter.onUploadProgress = function (json)
{
}

var upfiletpye = ""
$(document).click(function (ev)
{
    switch (ev.target.id) {
        case "shopplusbtn":
        case "xueshengzhengplusbtn":
        case "useravatarbtn":
            upfiletpye = ev.target.id;
            break;
    }
});
$("#useravatarbtn").click(function ()
{
    upfiletpye = this.id;
});
JsAdapter.onUpLoadReady = function ()
{
    JsAdapter.Progress({ "style": true, "message": "正在上传中..." }).Submit();
}
JsAdapter.onUpLoadFile = function (json)
{
    switch (upfiletpye) {
        case "xueshengzhengplusbtn":  //学生证
            $("#xueshengzheng").val(json["url"]);
            $("#xueshengzhengplus").html('<div><img src="' + upfilehost + json["url"] + '" /><h2></h2></div>').find("h2").click(function ()
            {
                $("#xueshengzhengplus").html('<a href="#selectephoto"><img id="xueshengzhengplusbtn" src="img/shop/plus.png" /></a>');
            });
            break;
        case "useravatarbtn":  //头像
            updateuserdata({ "avatar": json["url"] });
            $.post(apihost + "user/edit.php", { "avatar": json["url"], "myid": myid });
            break;
        case "shopplusbtn":  //市场商品发布
            var temp = $('<li><img src="' + upfilehost + json["url"] + '" /><input type="hidden" value="' + json["url"] + '"/><h2></h2></li>');
            var items = shopfabulist.find("li");
            temp.insertBefore(items.first());

            shopfabulist.find("input").each(function (idx)
            {
                $(this).attr("name", "tu" + (idx + 1));
            });
            shopfabulist.find('h2').click(function ()
            {
                $(this).parent().remove();
                if (!$("#shopplusbtn").length) {
                    shopfabulist.append('<li><a href="#selectephoto"><img id="shopplusbtn" src="img/shop/plus.png" /></a></li>');
                }
            });
            if (items.length >= 3) {
                items.last().remove();
            }
            break;
    }
    JsAdapter.Progress({ "action": "hide" }).Submit();
    history.back();
}
$("#selectephoto .right").click(function (ev)
{
    ev.preventDefault();
    if (photolist.find("input:checked").each(function (idx)
    {
        JsAdapter.Progress({ "style": true, "message": "正在上传中..." }).Submit();
        JsAdapter.UpLoadFile({ "transmarker": upfiletpye, "path": this.value, "cutwidth": 360, "ext": "" }).Submit();
    }).length == 0) {
        alert("请选择需要上传的图片！");
    }
});


//实名认证
$("#renzhengpage").load(function ()
{
    IsCloseRenZheng();
}).find("header .right").click(function ()
{
    if (IsLogin()) {
        JsAdapter.Progress({ "style": true, "message": "正在提交" }).Submit();
        $.post(apihost + "user/renzheng.php", $("#renzhengform").serialize() + "&myid=" + myid, function (data)
        {
            JsAdapter.Progress({ "action": "hide" }).Submit();
            alert(dictdata.infocode[data]);
            history.back();
        });
    }
});

//彩活动首页
var huodonglist = $("#huodonglist"), huodongid = 0, hdshijianquery = $("#hdshijianquery label"), hdswitch = $("#hdswitch"), hditemwrap = $("#hditemwrap"), hdsrcpoint = $("#hdsrcpoint");


hdswitch.find("ul").pageslide({
    "onslideend": function (json)
    {
        hdsrcpoint.find("span").removeClass("current").eq(json["curpage"] - 1).addClass("current")
    },
    "auto": 3000
});

var cuthuodong = $("#huodonglist"), huodongcurpage = 1, huodongtotalpage = 0;
hdshijianquery.click(function ()
{
    cuthuodong = $(this);
    var hdtick = new Date(systime);
    hdtick.setDate(hdtick.getDate() + $(this).index());
    hdtick.setHours(0);
    hdtick.setMinutes(0);
    hdtick.setSeconds(0);
    hdshijianquery.removeClass();
    $(this).addClass("selected");

    huodonglist.empty();
    //$.getJSON(apihost + "huodong/list.php", { "huodongshijian": parseInt(hdtick.getTime() / 1000), "curpage": huodongcurpage }, function (json)
    $.getJSON(javahost + "huodong/list", {"pageNum": huodongcurpage }, function (json)
    {
        huodongtotalpage = parseInt(json["totalpage"]);
        var html = json["data"].length ? '' : "<tr><td>无活动</td></tr>";
        $.each(json["data"], function (idx, data)
        {
        	
        	html +='<li>'
	            	+'<div style="width: 100%;height:100px;">'
	            	+'	<a shenghuoid="1 " href="#shenghuoviewpage">'
	            	+'	<div style="float: left;width: 30%;height: 100px;"><img style="width:100%; height:100%;" src="' + upfilehost + data["avatar"] + '"></div>'
	            	+'	<div class="new-mu_l2h" style="float: left;width: 70%;height:100px;">'
	            	+'		<div style="height: 30px;line-height: 10px;">'
	            	+'			<span class="huodongspan">'+data["title"]+'</span>'
	            	+'		</div>'
	            	+'		<div style="height: 70px;"><span class="description">'+data["neirong"]+'</span></div>'
	            	+'	</div>'
	            	+'	</a>'
	            	+'</div>'
	            	+'</li> ';
            //html += '<tr dataid="' + data["id"] + '"><td><div><img src="' + upfilehost + data["avatar"] + '" /></div></td><td><h2>' + data["nickname"] + '</h2><h3>' + new Date(data["huodongshijian"] * 1000).toString("HH:mm") + '</h3>' + data["title"] + '</td><td><img src="img/huodong/f' + data["fenleiid"] + '.png" /><h4>' + dictdata["hdfenleiid"][data["fenleiid"]] + '</h4></td></tr>';
        });
        html = $(html);

        if (huodongcurpage != 1 && huodongcurpage < huodongtotalpage) {
            huodonglist.append(html);
            huodongcurpage++;
        }
        else {
            huodonglist.html(html);
        }

        html.filter("[dataid]").click(function ()
        {
            huodongid = $(this).attr("dataid");
            location.href = "#huodongview";
        });
    });

}).first().click();



function huodonglistview(){
		    cuthuodong = $(this);
		    var hdtick = new Date(systime);
		    hdtick.setDate(hdtick.getDate() + $(this).index());
		    hdtick.setHours(0);
		    hdtick.setMinutes(0);
		    hdtick.setSeconds(0);
		    hdshijianquery.removeClass();
		    $(this).addClass("selected");
		    huodonglist.empty();
		    //$.getJSON(apihost + "huodong/list.php", { "huodongshijian": parseInt(hdtick.getTime() / 1000), "curpage": huodongcurpage }, function (json)
		    $.getJSON(javahost + "huodong/list", {"pageNum": huodongcurpage }, function (json)
		    {
		        huodongtotalpage = parseInt(json["totalpage"]);
		        var html = json["data"].length ? '' : "<tr><td>无活动</td></tr>";
		        $.each(json["data"], function (idx, data)
		        {
		        	html +='<li class="hd" dataid="'+ data["id"]+'">'
		            	+'<div  style="width: 100%;height:100px;">'
		            	+'	<a  href="javascript:void(0);">'
		            	+'	<div style="float: left;width: 30%;height: 100px;"><img class="huodongimg" src="' + upfilehost + data["avatar"] + '"></div>'
		            	+'	<div class="new-mu_l2h" style="float: left;width: 70%;height:100px;">'
		            	+'		<h1 class="hdtitle">'
		            	+'			<span class="huodongspan">'+data["title"]+'</span>'
		            	+'		</h1>'
		            	+'		<span class="description">'+data["neirong"]+'</span>'
		            	+'	</div>'
		            	+'	</a>'
		            	+'</div>'
		            	+'</li> ';
		            //html += '<tr dataid="' + data["id"] + '"><td><div><img src="' + upfilehost + data["avatar"] + '" /></div></td><td><h2>' + data["nickname"] + '</h2><h3>' + new Date(data["huodongshijian"] * 1000).toString("HH:mm") + '</h3>' + data["title"] + '</td><td><img src="img/huodong/f' + data["fenleiid"] + '.png" /><h4>' + dictdata["hdfenleiid"][data["fenleiid"]] + '</h4></td></tr>';
		        });
		        html = $(html);
		        if (huodongcurpage != 1 && huodongcurpage < huodongtotalpage) {
		            huodonglist.append(html);
		            huodongcurpage++;
		        }
		        else {
		            huodonglist.html(html);
		        }

		        html.filter("[dataid]").click(function ()
		        {
		            huodongid = $(this).attr("dataid");
		            location.href = "#huodongview";
		        });
		        loaded();
		    });
}

$("#huodongpage").load(function ()
{
    hdsrcpoint.empty();
    //$.getJSON(apihost + "huodong/advert/list.php", function (json)
    $.getJSON(javahost + "huodong/advert/list",{ "pageNum": 1 }, function (json)
    {
        var html = '';
        $.each(json, function (k, v)
        {
            html += '<li dataid="' + v["huodongid"] + '"><a href="#huodongview"><img src="' + upfilehost + v["ico"] + '" /></a></li>';
            hdsrcpoint.append('<span></span>');
        });
        hdsrcpoint.find("span").first().addClass("current");
        hdswitch.find(">ul").html(html).find("li").width(winw);
        hdswitch.find(">ul").width(winw * hdswitch.find("li").length);
        hdswitch.find("li").click(function ()
        {
            huodongid = $(this).attr("dataid");
        });
    });
    huodonglistview();
    //hdshijianquery.first().click();
});

$("#hditemwrap").moveajax({
	"update": function ()
    {
        cuthuodong.click();
    },
    "next": function ()
    {
        cuthuodong.click();
    }
});

$("#zujubtn").click(function ()
{
    if (IsLogin() && IsRenZheng()) {
        $(this).parent().hide().next().show();
    }
});

//选择活动类型
$("#huodongslide").selectslide({
    "data": [dictdata.hdfenleiid], "dis": 20, "onslideend": function (json)
    {
        $("#zjleixing").val(json["curpage"]);
    }
});

$("#zjleixingvalbtn,#fenleiidwrab").click(function ()
{
    $("#tipsmsgwrap,#huodongselectwrap").show();
    var curpage = ($("#fenleiid").val() || 1) - 1;
    $("#huodongleixing").css("margin-top", -$("#huodongleixing li").first().outerHeight() * curpage).attr("curpage", curpage);
});
$("#huodongselectwrap button").click(function ()
{
    var zjleixing = parseInt($("#huodongleixing").attr("curpage")) + 1;
    $("#zjleixing").val(zjleixing);
    $("#zjleixingval").html('<img src="img/huodong/f' + zjleixing + '.png" /><h3>' + dictdata.hdfenleiid[zjleixing] + '</h3>').show();
    $("#fenleiid").val(zjleixing).next().html(dictdata.hdfenleiid[zjleixing]);
    $("#tipsmsgwrap,#huodongselectwrap").hide();
    if (huodongjieshaopageright.hasClass("allow") && $("#huodongshijian").val() && $("#zjleixing").val()) {
        $("#hdzuju>li").hide().last().show();
    }
});

//时间按钮
var hdshijianval = new Date().getTime();
$("#zjshijianbtn").click(function ()
{
    $("#tipsmsgwrap,#shijianselectwrap").attr("transmarker", "hdshijianval").show();
    //JsAdapter.DateTimePicker({ "transmarker": "hdshijianval","timetick": hdshijianval,"min": systimetick*1000 }).Submit();
});

$("#shijianselectwrap button").click(function (e)
{
    var selectminutesitem = $("#selectminutesitem"), selecthouritem = $("#selecthouritem"), selectyearitem = $("#selectyearitem");
    var dt = new Date(selectyearitem.find("li").eq(selectyearitem.attr("curpage")).attr("time") * 1);
    var json = { "transmarker": $("#shijianselectwrap").attr("transmarker"), "year": dt.getFullYear(), "month": dt.getMonth(), "day": dt.getDate(), "hour": selecthouritem.find("li").eq(selecthouritem.attr("curpage")).attr("time"), "minute": selectminutesitem.find("li").eq(selectminutesitem.attr("curpage")).attr("time") };
    JsAdapter.onDateTimePicker(json);
    $("#tipsmsgwrap,#shijianselectwrap").hide()
});

$("#zjjsvalbtn").click(function ()
{
    location.href = "#huodongjieshaopage";
});

//活动介绍确认按钮
$("#huodongjieshaopage,#shopfabupage").load(function ()
{
    IsRenZheng();
}).unload(function ()
{
    IsCloseRenZheng();
});


var huodongjieshaopageright = $("#huodongjieshaopage .right");
$("#huodongzhuti,#huodongjieshao").keyup(function ()
{
    if ($("#huodongzhuti").val().length > 1 && $("#huodongjieshao").val().length > 1) {
        huodongjieshaopageright.removeClass("disabled").addClass("allow");
        $("#zjjsval").show();
    }
    else {
        $("#zjjsval").hide();
        huodongjieshaopageright.removeClass("allow").addClass("disabled");
    }
});
huodongjieshaopageright.click(function (ev)
{
    ev.preventDefault();
    if (huodongjieshaopageright.hasClass("allow") && $("#huodongshijian").val() && $("#zjleixing").val()) {
        $("#hdzuju>li").hide().last().show();
    }
    history.back();
});

$("#hdbackbtn").click(function ()
{
    $("#hdzuju>li").hide().eq(1).show();
});

//活动发布 
$("#hdhdfabubtn").click(function ()
{
    try {
        var huodongshijian = $("#huodongshijian").val();
        if (!huodongshijian || parseInt(huodongshijian) < systimetick) {
            throw "14";
        }
        var hdtitle = $("#huodongzhuti").val().replace(/\s+/, "");
        if (hdtitle.length < 3) {
            throw '9';
        }
        var hdneirong = $("#huodongjieshao").val();
        if (hdneirong < 5) {
            throw '10';
        }
        hdneirong = hdneirong.replace(/\n/mg, "<br />");
        JsAdapter.Progress({ "style": true, "message": "正在发布" }).Submit();
        $.post(javahost + "huodong/edit", { "action": "append", "huodongshijian": huodongshijian, "title": hdtitle, "neirong": hdneirong, "fenleiid": $("#zjleixing").val(), "myid": myid }, function (data)
        {
            JsAdapter.Progress({ "action": "hide" }).Submit();

            $("#hdzujuset p").hide();
            $("#fenleiid,#zjleixing,#huodongshijian,#huodongzhuti,#huodongjieshao").val("");
            $("#hdzuju>li").hide().first().show();
            huodongjieshaopageright.removeClass("allow");

            if (data == "12") {
                alert("发布成功！");
                return;
            }
            alert(data);
        });
    }
    catch (e) {
        alert(dictdata.infocode[e]);
    }
});

//彩活动详情页
var huodongbaomingbtn = $("#huodongview header .right"), huodongliuyanlist = $("#huodongliuyanlist"), huodonginfo = $("#huodonginfo");

$("#huodongview").load(function ()
{
    IsLogin(true);

    huodonginfo.html("<br /><br /><br />").removeClass("hide");
    huodongbaomingbtn.addClass("allow").removeClass("disabled3").html("报名").unbind().click(function (ev)
    {
        ev.preventDefault();
    });
    $.getJSON(javahost + "huodong/view", { "id": huodongid, "myid": myid }, function (data)
    {

        ShareData.title = data["title"];
        ShareData.desc = data["neirong"];
        ShareData.imgurl = wwwhost + "img/f" + data["fenleiid"] + ".png";

        ShareData.url = javahost + "h5/huodong?id=" + huodongid;

        if (data["isbaoming"]) {
            huodongbaomingbtn.removeClass("allow").addClass("disabled3").html("已报名");
        }
        else {
            huodongbaomingbtn.click(function (ev)
            {
                if (!IsLogin()) {
                    return;
                }
                JsAdapter.Progress({ "style": true, "message": "正在报名" }).Submit();
                $.post(javahost + "huodong/baoming/edit", { "huodongid": huodongid, "myid": myid }, function ()
                {
                    JsAdapter.Progress({ "action": "hide" }).Submit();
                    huodongbaomingbtn.unbind().removeClass("allow").addClass("disabled3").html("已报名").click(function (ev)
                    {
                        ev.preventDefault();
                    });
                    $("#yibaoming").append('<li><img src="' + upfilehost + userdata["avatar"] + '" /></li>');
                });
            });
        }

        var html = '<table><tr><td><div><img src="' + upfilehost + data["avatar"] + '" /></div></td><td><h2>' + data["nickname"] + '</h2><h3>' + new Date(data["huodongshijian"] * 1000).toString("HH:mm<h2>yyyy-MM-dd</h2>") + '</h3></td><td><img src="img/huodong/f' + data["fenleiid"] + '.png" /><h4>' + dictdata.hdfenleiid[data["fenleiid"]] + '</h4></td></tr></table><h5>' + data["title"] + '</h5><p>' + data["neirong"] + '</p>';


        huodonginfo.html(html).addClass("hide");
    });

    $.getJSON(javahost + "huodong/baoming/list", { "huodongid": huodongid }, function (json)
    {
        var html = json.length ? '' : '<p>还没有人报名！</p>';


        $.each(json, function (idx, data)
        {
            html += '<li><img src="' + upfilehost + data["avatar"] + '" /></li>';
        });

        $("#yibaoming").html(html);
    });
    huodongliuyanlist.empty();
    $.getJSON(javahost + "huodong/liuyan/list", { "huodongid": huodongid }, function (json)
    {
        var html = "";
        $.each(json['data'], function (idx, data)
        {
            html += '<li nickname="' + data["nickname"] + '"><table><tr><td><div><img src="' + upfilehost + data["avatar"] + '" /></div></td><td>' + data["nickname"] + '</td><td>' + new Date(data["shijian"] * 1000).toString("yyyy-MM-dd HH:mm:ss") + '</td></tr></table><p>' + (data["neirong"].replace(/(@[^\s]+)/, '回复<span>$1</span>')) + '</p></li>';
        });
        huodongliuyanlist.html(html);
        huodongliuyanlist.find("[nickname]").click(function ()
        {
            $("#huodongliuyan").val("@" + $(this).attr("nickname") + " ").focus();
        });
    });
}).unload(function ()
{
    $("#tipsmsgwrap,#tipsmsg").hide();
});
$("#huodongliuyanbtn").click(function ()
{
    var neirong = $("#huodongliuyan").val();
    if (IsLogin()) {
        $("#huodongliuyan").val("");
        $.post(javahost + "huodong/liuyan/edit", { "neirong": neirong, "huodongid": huodongid, "myid": myid }, function ()
        {
            var html = '<li nickname="' + userdata["nickname"] + '"><table><tr><td><div><img src="' + upfilehost + userdata["avatar"] + '" /></div></td><td>' + userdata["nickname"] + '</td><td>' + new Date().toString("yyyy-MM-dd HH:mm:ss") + '</td></tr></table><p>' + (neirong.replace(/(@[^\s]+)/, '回复<span>$1</span>')) + '</p></li>';
            if (huodongliuyanlist.find(">li").length) {
                $(html).insertBefore(huodongliuyanlist.find(">li").first()).click(function ()
                {
                    $("#huodongliuyan").val("@" + $(this).attr("nickname") + " ").focus();
                });
            }
            else {
                huodongliuyanlist.append(html).find("li").first().click(function ()
                {
                    $("#huodongliuyan").val("@" + $(this).attr("nickname") + " ").focus();
                });
            }
        });
    }
});


$("#tipsmsgwrap").click(function ()
{
    $("#tipsmsg,#tipsmsgwrap,#huodongselectwrap,#shijianselectwrap,#sharewrap,#hdsharewrap").hide();
});

//我发布的活动
var myhuodong = $("#myhuodong"), myhuodongart = myhuodong.find(".load"), myhdlist = $("#myhuodong ul"), myhuodongid = 0, myhuodongcurpage = 1, myhuodongtotalpage = 0;
myhuodong.load(function ()
{
    if (IsLogin()) {
        var html = "";
        $.getJSON(javahost + "user/huodong", { "myid": myid, "pageNum": myhuodongcurpage }, function (json)
        {
            myhuodongtotalpage = parseInt(json["totalpage"]);
            $.each(json["data"], function (idx, data)
            {
                html += '<li><table><tr><td><img src="img/huodong/f' + data['fenleiid'] + '.png" /><h4>' + dictdata.hdfenleiid[data['fenleiid']] + '</h4></td><td><h2 dataid="' + data["id"] + '">' + (data["title"].length > 10 ? data["title"].substring(0, 10) : data["title"]) + '</h2><h3>发布时间：' + new Date(data['shijian'] * 1000).toString('yyyy-MM-dd') + '<a myhuodongid="' + data["id"] + '" href="#edithuodong">编辑</a></h3></td><td delete="' + data["id"] + '">删除</td></tr></table></li>';
            });

            html = $(html);

            html.find("[delete]").click(function ()
            {
                $(this).parent().parent().parent().parent().remove();
                $.getJSON(javahost + "huodong/delete", { "id": $(this).attr("delete") }, function (data)
                {
                    alert(dictdata.infocode[data]);
                });
            });

            html.find("[dataid]").click(function ()
            {
                huodongid = $(this).attr("dataid");
                location.href = "#huodongview";
            });

            myhuodongart.addClass("hide");
            html.find("[myhuodongid]").click(function ()
            {
                myhuodongid = $(this).attr("myhuodongid");
            });

            if (myhuodongcurpage > 1) {
                myhdlist.append(html);
            }
            else {
                myhdlist.html(html);
            }
            myhuodongart.unbind().moveajax({
                "slide": true,
                "update": function (json)
                {
                },
                "next": function (json)
                {
                    if (myhuodongcurpage < myhuodongtotalpage) {
                        myhuodongcurpage++;
                        myhuodong.load();
                    }
                }
            });
        });
    }
});

//编辑活动加载数据
var edithuoart = $("#edithuodong article");
$("#edithuodong").load(function ()
{
    if (myhuodongid) {
        edithuoart.removeClass("hide");
        $("#fenleiid").val('');
        $("#hdtitle").val('');
        $("#hdneirong").val('');
        $.getJSON(javahost + "huodong/view", { "id": myhuodongid }, function (json)
        {
            edithuoart.addClass("hide");
            $("#fenleiid").val(json['fenleiid']).next().html(dictdata.hdfenleiid[json['fenleiid']]);
            JsAdapter.onDateTimePicker(json["huodongshijian"] * 1000);
            $("#hdtitle").val(json["title"]);
            $("#hdneirong").val(json["neirong"].replace(/<br \/>/mg,"\n"));
        });
    }
});

//选择活动时间
var datetimepicker = $("#datetimepicker"), timetick = 0;

JsAdapter.onDateTimePicker = function (json)
{
    var dt = isNaN(json) ? new Date(json["year"], json["month"], json["day"], json["hour"], json["minute"]) : new Date(json);
    timetick = dt.getTime();
    $("#huodongshijian").val(parseInt(timetick / 1000));
    switch (json["transmarker"]) {
        case "hdshijianval":
            $("#zjshijianval").html(dt.toString("<h2>HH:mm</h2><h3>MM月dd日</h3>")).show();
            if ($("#zjleixing").val() && huodongjieshaopageright.hasClass("allow")) {
                $("#hdzuju>li").hide().last().show();
            }
            break;
        default:
            datetimepicker.html(dt.toString("yyyy月MM月dd日 HH时mm分"));
            break;
    }
}
$("#datetimepicker").click(function ()
{
    $("#tipsmsgwrap,#shijianselectwrap").removeAttr("transmarker").show();
    var dt = new Date(timetick || new Date().getTime());

    var curdt = new Date(dt);
    curdt.setHours(0);
    curdt.setMinutes(0);
    curdt.setSeconds(0);
    curdt.setMilliseconds(0);
    var selecthouritem = $("#selecthouritem");
    var curpage = selecthouritem.find("[time=" + dt.getHours() + "]").index() || 0;
    selecthouritem.css("margin-top", -curpage * selecthouritem.children().first().outerHeight()).attr("curpage", curpage);

    var selectminutesitem = $("#selectminutesitem");
    curpage = selectminutesitem.find("[time=" + dt.getMinutes() + "]").index() || 0;
    selectminutesitem.css("margin-top", -curpage * selectminutesitem.children().first().outerHeight()).attr("curpage", curpage);

    var selectyearitem = $("#selectyearitem");
    curpage = selectyearitem.find("[time=" + curdt.getTime() + "]").index() || 0;
    selectyearitem.css("margin-top", -curpage * selectyearitem.children().first().outerHeight()).attr("curpage", curpage);

    // JsAdapter.DateTimePicker({ "timetick": timetick||new Date().getTime(),"min": systimetick*1000 }).Submit();
});

$("#edithuodong a.right").click(function (ev)
{
    ev.preventDefault();
    try {
        if (!myhuodongid) {
            throw '11';
        }
        if ($("#hdtitle").val().replace(/\s+/, "").length < 3) {
            throw '9';
        }
        if ($("#hdneirong").val().replace(/\s+/, "").length < 5) {
            throw '10';
        }
        JsAdapter.Progress({ "style": true, "message": "正在提交" }).Submit();
        $.post(javahost + "huodong/edit", $("#huodongform").serialize() + "&id=" + myhuodongid, function (data)
        {
            JsAdapter.Progress({ "action": "hide" }).Submit();
            alert(dictdata.infocode[data]);
            history.back();
        });
    }
    catch (e) {
        alert(dictdata.infocode[e]);
    }

});
JsAdapter.onGetNetState = function (json)
{
    if (json["state"]) {
        $("#netstatepage").hide();
    }
    else {
        allpage.hide();
        $("#netstatepage").show();
    }
}
JsAdapter.GetNetState({}).Submit();

$("#resetnet").click(function ()
{
    JsAdapter.GetNetState({}).Submit();
    location.reload();
});

$("#usereditpage header .right").click(function ()
{
    if (IsLogin()) {
        var nickname = $("#editnickname").val();

        $.post(javahost + "user/edit", { "nickname": nickname, "myid": myid }, function (data)
        {
            updateuserdata({ "nickname": nickname });
            history.back();
        });
    }
});

//会员数据本地缓存处理
function updateuserdata(json)
{
    $.extend(userdata, json);
    Storage.Set("userdata", Object.toJson(userdata));

    userdataRefresh();
}

var gerenxinxi = $("#gerenxinxi");
function userdataRefresh()
{
    $("#dizhi").val(userdata["dizhi"]);
    $("#dizhiwrap").removeClass();
    if (userdata["dizhi"]) {
        $("#dizhiwrap").addClass("allow");
        $("#dizhiwrap td").first().html((userdata["shengid"] != undefined && areadata[userdata["shengid"]] ? areadata[userdata["shengid"]][0] : "") + (areadata[userdata["shiid"]] ? areadata[userdata["shiid"]][0] : "") + (areadata[userdata["xianid"]] ? areadata[userdata["xianid"]][0] : "") + userdata["dizhi"]);
    }
    $("#dizhipage li a").first().html((areadata[userdata["shengid"]] ? areadata[userdata["shengid"]][0] : "") + (areadata[userdata["shiid"]] ? areadata[userdata["shiid"]][0] : "") + (areadata[userdata["xianid"]] ? areadata[userdata["xianid"]][0] : "") || "请选择区域");

    $("#useravatar").attr("src", upfilehost + userdata["avatar"]);
    var html = '<td><div><a href="#usercenterpage"><img src="' + upfilehost + userdata["avatar"] + '" /></a></div></td><td><h2>' + userdata["nickname"] + '</h2><h5>';

    $("#shibaiwrap").hide();
    switch (userdata["isrenzheng"]) {
        case 0:
            html += '<a href="#renzhengpage">点击认证</a>';
            break;
        case 1:
            html += '<a href="#yirenzhengpage"><img src="img/user/rzz.png" /></a>认证中';
            break;
        case 2:
            html += '<a href="#yirenzhengpage"><img src="img/user/rz.png" /></a>';
            break;
        case 3:
            html += '<img src="img/user/rz.png" /><a href="#renzhengpage">重新认证</a>';
            $("#shibaiwrap").show().html('失败原因：' + userdata["shibaiyuanyin"]);
            break;
    }
    html += '</h5></td><td><h3>积分钱包</h3><h4>' + userdata["jifen"] + '</h4></td>';
    gerenxinxi.html(html);

    $("#editnickname").val(userdata["nickname"]);
    $("#usernickname").html(userdata["nickname"]);

    $("#realname").val(userdata["realname"] || "");
    $("[name='sex']").val([userdata["sex"]]);
    $("#xuexiao").val(userdata["xuexiao"] || "");
    $("#xuehao").val(userdata["xuehao"] || "");
    $("#xueshengzheng").val(userdata["xueshengzheng"] || "");

    if (userdata["xueshengzheng"]) {
        $("#xueshengzhengplus").html('<div><img src="' + upfilehost + userdata["xueshengzheng"] + '" /><h2></h2></div>').find("h2").click(function ()
        {
            $("#xueshengzhengplus").html('<a href="#selectephoto"><img id="xueshengzhengplusbtn" src="img/shop/plus.png" /></a>');
        });
    }

    $("#yirealname").html(userdata["realname"]);
    $("#yisex").html(dictdata.sex[userdata["sex"]] || "");
    $("#yixuexiao").html(userdata["xuexiao"]);
    $("#yixuehao").html(userdata["xuehao"]);
    $("#yishili").html('<div><img src="' + upfilehost + userdata["xueshengzheng"] + '" /></div>');

}

var ShareData = { "title": "", "desc": "", "url": "", "imgurl": "http://sys.caidan360.com/img/logo.png" };
$("[sharetarget]").click(function ()
{
    ShareData["target"] = $(this).attr("sharetarget");
    if (ShareData.title.length > 30) {
        ShareData.title = ShareData.title.substring(0, 30);
    }
    if (ShareData.desc.length > 140) {
        ShareData.desc = ShareData.desc.substring(0, 140);
    }
    $("#tipsmsgwrap,#sharewrap,#hdsharewrap").hide();
    JsAdapter.Share(ShareData).Submit();
});

$("[sharemore],#yibaomingde span").click(function ()
{
    $("#tipsmsgwrap,#hdsharewrap").show();
});

JsAdapter.onGetPackageSign = function (data)
{

}
JsAdapter.GetPackageSign().Submit();



//区域设置
var areadata = {};
$.getJSON(javahost + "area/list", function (data)
{
    var html = '', parentid = 0;
    areadata = data;
    updateuserdata();
    $.each(areadata, function (k, v)
    {
        if (v[1] == parentid) {
            html += '<li><input type="radio" id="area' + k + '" name="shengid" value="' + k + '" /><label for="area' + k + '">' + v[0] + '<label></li>';
        }
    });
    var shengid = 0, shiid = 0, xianid = 0;
    $("#shengid").html(html).find("input").click(function ()
    {
        shengid = this.value;
        html = '';
        $.each(areadata, function (k, v)
        {
            if (v[1] == shengid) {
                html += '<li><input type="radio" id="area' + k + '" name="shiid" value="' + k + '" /><label for="area' + k + '">' + v[0] + '<label></li>';
            }
        });
        $("#shiid").html(html).find("input").click(function ()
        {
            shiid = this.value;
            html = '';
            $.each(areadata, function (k, v)
            {
                if (v[1] == shiid) {
                    html += '<li><input type="radio" id="area' + k + '" name="xianid" value="' + k + '" /><label for="area' + k + '">' + v[0] + '<label></li>';
                }
            });
            $("#xianid").html(html).find("input").click(function ()
            {
                xianid = this.value;
                $("#dizhipage li a").first().html(areadata[shengid][0] + areadata[shiid][0] + areadata[xianid][0]);
                history.back();
            }).first().prop("checked", true);
        }).first().click();
    }).first().click();
});
$("#quyupage").load(function ()
{
    if (userdata["xianid"]) {
        $("[name=xianid][value=" + userdata["xianid"] + "]").prop("checked", true);
    }
});

JsAdapter.onReady = function (json)
{
    //prikey=json["prikey"];
}
function loaded() { 
	var myScroll,  
	pullDown = $("#pullDown"),  
	pullUp = $("#pullUp"),  
	pullDownLabel = $(".pullDownLabel"),  
	pullUpLabel = $(".pullUpLabel"),  
	container = $('#huodonglist'),  
	loadingStep = 0;//加载状态0默认，1显示加载状态，2执行加载数据，只有当为0时才能再次加载，这是防止过快拉动刷新  
	pullDown.hide(myScroll);  
	pullUp.hide(); 
    myScroll = new IScroll("#wrapper", {  
        scrollbars: true,  
        mouseWheel: false,  
        click: true,
        interactiveScrollbars: true,  
        shrinkScrollbars: 'scale',  
        fadeScrollbars: true,  
        scrollY:true,  
        probeType: 2,  
        bindToWrapper:true  
    });  
        myScroll.on("scroll",function(){  
            if(loadingStep == 0 && !pullDown.attr("class").match('refresh|loading') && !pullUp.attr("class").match('refresh')){  
                if(this.y > 40){//下拉刷新操作  
                    $(".pulldown-tips").hide();  
                    pullDown.addClass("refresh").show();  
                    pullDownLabel.text("松手刷新数据");  
                    loadingStep = 1;  
                    myScroll.refresh();  
                }else if(this.y < (this.maxScrollY - 14)){//上拉加载更多  
                    pullUp.addClass("refresh").show();  
                    pullUpLabel.text("正在载入");  
                    loadingStep = 1;  
                    pullUpAction();  
                }  
            }  
        });  
        myScroll.on("scrollEnd",function(){  
            if(loadingStep == 1){  
                if( pullDown.attr("class").match("refresh") ){//下拉刷新操作  
                    pullDown.removeClass("refresh").addClass("loading");  
                    pullDownLabel.text("正在刷新");  
                    loadingStep = 2;  
                    pullDownAction();  
                }  
            }  
        });  

    function pullDownAction(){  
        setTimeout(function(){  
        	$("#huodongpage").load();
            var li, i;  
            $.getJSON(javahost + "huodong/list", {"pageNum": 1 }, function (json)
            	    {
            	        huodongtotalpage = parseInt(json["totalpage"]);
            	        var html = json["data"].length ? '' : "<tr><td>无活动</td></tr>";
            	        $.each(json["data"], function (idx, data)
            	        {
            	        	
            	        	html +='<li class="hd" dataid="'+ data["id"]+'">'
    		            	+'<div  style="width: 100%;height:100px;">'
    		            	+'	<a  href="javascript:void(0);">'
    		            	+'	<div style="float: left;width: 30%;height: 100px;"><img class="huodongimg" src="' + upfilehost + data["avatar"] + '"></div>'
    		            	+'	<div class="new-mu_l2h" style="float: left;width: 70%;height:100px;">'
    		            	+'		<h1 class="hdtitle">'
    		            	+'			<span class="huodongspan">'+data["title"]+'</span>'
    		            	+'		</h1>'
    		            	+'		<span class="description">'+data["neirong"]+'</span>'
    		            	+'	</div>'
    		            	+'	</a>'
    		            	+'</div>'
    		            	+'</li> ';
            	        });
            	        html = $(html);

            	        if (huodongcurpage != 1 && huodongcurpage < huodongtotalpage) {
            	            huodonglist.append(html);
            	            huodongcurpage++;
            	        }
            	        else {
            	            huodonglist.html(html);
            	        }

            	        html.filter("[dataid]").click(function ()
            	        {
            	            huodongid = $(this).attr("dataid");
            	            location.href = "#huodongview";
            	        });
            	    });
            pullDown.attr('class','').hide();  
            myScroll.refresh();  
            loadingStep = 0;  
            $(".pulldown-tips").show();  
        },1000);  
    }  
    function pullUpAction(){  
        setTimeout(function(){  
        	$("#huodongpage").load();
            var li, i;  
            huodongcurpage++;
            $.getJSON(javahost + "huodong/list", {"pageNum": huodongcurpage }, function (json)
    	    {
    	        huodongtotalpage = parseInt(json["totalpage"]);
    	        var html = json["data"].length ? '' : "<tr><td>无活动</td></tr>";
    	        $.each(json["data"], function (idx, data)
    	        {
    	        	
    	        	html +='<li class="hd" dataid="'+ data["id"]+'">'
	            	+'<div  style="width: 100%;height:100px;">'
	            	+'	<a  href="javascript:void(0);">'
	            	+'	<div style="float: left;width: 30%;height: 100px;"><img class="huodongimg" src="' + upfilehost + data["avatar"] + '"></div>'
	            	+'	<div class="new-mu_l2h" style="float: left;width: 70%;height:100px;">'
	            	+'		<h1 class="hdtitle">'
	            	+'			<span class="huodongspan">'+data["title"]+'</span>'
	            	+'		</h1>'
	            	+'		<span class="description">'+data["neirong"]+'</span>'
	            	+'	</div>'
	            	+'	</a>'
	            	+'</div>'
	            	+'</li> ';
    	        });
    	        html = $(html);

    	        if (huodongcurpage != 1 && huodongcurpage < huodongtotalpage) {
    	            huodonglist.append(html);
    	            huodongcurpage++;
    	        }
    	        else {
    	            huodonglist.html(html);
    	        }

    	        html.filter("[dataid]").click(function ()
    	        {
    	            huodongid = $(this).attr("dataid");
    	            location.href = "#huodongview";
    	        });
    	    });
            
            
            pullUp.attr('class','').hide();  
            myScroll.refresh();  
            loadingStep = 0;  
        },1000);  
    }  
}  


//JsAdapter.Share({ "target": "qqshare","url": "http://www.rsseasy.com","title": "中企聚易","desc": "致力于帮助更多的人","imgurl": "http://www.rsseasy.com/img/logo.png" }).Submit();
